package com.ws.base.common.datadict.service.impl;

import java.util.List;

import com.ws.base.common.datadict.dao.DatadictDao;
import com.ws.base.common.datadict.entity.Datadict;
import com.ws.base.common.datadict.entity.Datadictdetail;
import com.ws.base.common.datadict.service.DatadictService;
import com.ws.base.common.util.WSUtil;

public class DatadictServiceImpl implements DatadictService {
    private DatadictDao datadictDao;

    public DatadictDao getDatadictDao() {
        return datadictDao;
    }

    public void setDatadictDao(DatadictDao datadictDao) {
        this.datadictDao = datadictDao;
    }

    public Datadict getDatadictById(String datadictId) {
        Datadict datadict = null;
        List<Datadictdetail> datadictdetails = datadictDao
                .getDatadictById(datadictId);

        if (!WSUtil.isEmpty(datadictdetails)) {
            datadict = new Datadict();

            for (Datadictdetail datadictdetail : datadictdetails) {
                if (datadictdetail.getDatadictId().equals(
                        datadictdetail.getTypeId())) {
                    datadict.setDatadictId(datadictdetail.getDatadictId());
                    datadict.setDescription(datadictdetail.getDescription());
                    datadictdetails.remove(datadictdetail);
                    break;
                }
            }

            for (Datadictdetail datadictdetail : datadictdetails) {
                datadict.getDatadictdetailMap().put(
                        datadictdetail.getDatadictId(), datadictdetail);
            }

            datadict.setDatadictdetails(datadictdetails);
        }

        return datadict;
    }
}
